package com.example.boot.express;

import com.example.boot.express.data.query.OrderQuery;
import com.example.boot.express.operator.JoinOperator;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;

public class ExpressSimpleTest {

    public static void main(String[] args) {
        addFunction();
    }


    public static void add() {
        try {
            ExpressRunner runner = new ExpressRunner();
            DefaultContext<String, Object> context = new DefaultContext<String, Object>();
            context.put("a",1);
            context.put("b",2);
            context.put("c",3);
            String express = "if(a < b) {System.out.println('a大于b')}else{System.out.println('a:' + a)}";
            Object r = runner.execute(express, context, null, true, false);
            System.out.println(r);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void opObj() {
        try {
            ExpressRunner runner = new ExpressRunner();
            DefaultContext<String, Object> context = new DefaultContext<>();
            context.put("orderQuery", new OrderQuery());
            runner.addMacro("OrderQuery", OrderQuery.class.getName());
            String statement = "query = new OrderQuery();";
            Object r = runner.execute(statement, context, null, false, false);
            System.out.println(r);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void addFunction() {
        try {
            ExpressRunner runner = new ExpressRunner();
            DefaultContext<String, Object> context = new DefaultContext<String, Object>();
            runner.addFunction("join",new JoinOperator());
            Object r = runner.execute("join(1,2,3)", context, null, false, false);
            System.out.println(r);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
